{{IF [[accessControl.hasPermission([[$DAccessControl::RUN_TASK_ACCESS]])]]}}
  <h3>Create supertask:</h3>
  <div class="card">
    <div class="table-responsive">
      <table class="table table-bordered">
        <tr>
          <th>ID</th>
          <th>Name</th>
          <th>&nbsp;</th>
        </tr>
        {{FOREACH supertask;[[superTasks]]}}
          <tr>
            <td>
              <a href="supertasks.php?id=[[supertask.getId()]]">[[supertask.getId()]]</a>
            </td>
            <td>
              <a href="supertasks.php?id=[[supertask.getId()]]">[[supertask.getSupertaskName()]]</a>
            </td>
            <td>
              <form class='form-inline' action="supertasks.php" method="POST">
                <input type='hidden' name='action' value='[[$DSupertaskAction::APPLY_SUPERTASK]]'>
                <input type='hidden' name='supertask' value='[[supertask.getId()]]'>
                <input type="hidden" name="csrf" value="[[csrf]]">
                <input type="hidden" name="hashlist" value="[[list.getVal('hashlist')->getId()]]">
                <select name="crackerBinaryTypeId" id="crackerBinaryTypeId-[[supertask.getId()]]" class="form-control mx-1" title="Cracker Binary">
                  {{FOREACH binary;[[binaries]]}}
                    <option value="[[binary.getId()]]">[[binary.getTypeName()]]</option>
                  {{ENDFOREACH}}
                </select>
                <select name="crackerBinaryVersionId" id="crackerBinaryVersionId-[[supertask.getId()]]" class="form-control mx-1" title="Binary Version">
                  <option value="0">&nbsp;</option>
                </select>
                <script type="text/javascript">
                    var versions = [];
                    {{FOREACH version;[[versions]]}}
                      if ([[version.getCrackerBinaryTypeId()]] in versions) {
                          versions[ [[version.getCrackerBinaryTypeId()]] ].push(["[[version.getVersion()]]", [[version.getId()]] ]);
                      }
                      else{
                          versions [ [[version.getCrackerBinaryTypeId()]] ] = [ ["[[version.getVersion()]]", [[version.getId()]] ] ];
                      }
                    {{ENDFOREACH}}

                    configureDropDownLists(document.getElementById('crackerBinaryTypeId-[[supertask.getId()]]'), document.getElementById('crackerBinaryVersionId-[[supertask.getId()]]'));
                    $("#crackerBinaryType").change(function() {
                        configureDropDownLists(document.getElementById('crackerBinaryTypeId-[[supertask.getId()]]'), document.getElementById('crackerBinaryVersionId-[[supertask.getId()]]'));
                    });

                    function configureDropDownLists(ddl1, ddl2) {
                        ddl2.options.length = 0;
                        if (ddl1.value.length === 0) {
                            return;
                        }
                        for (i = 0; i < versions[ddl1.value].length; i++){
                            createOption(ddl2, versions[ddl1.value][i][0], versions[ddl1.value][i][1]);
                        }
                    }

                    function createOption(ddl, text, value) {
                        var opt = document.createElement('option');
                        opt.value = value;
                        opt.text = text;
                        ddl.options.add(opt);
                    }
                </script>
                <input type="submit" class='btn {{IF [[toggledarkmode]] > 0}}btn-primary{{ELSE}}btn-light{{ENDIF}} mx-1' value="Create Supertask">
              </form>
            </td>
          </tr>
        {{ENDFOREACH}}
      </table>
    </div>
  </div>
{{ENDIF}}
